package org.goat.caprabank.client;

import org.goat.caprabank.shared.entity.User;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.RootPanel;

public class Caprabank implements EntryPoint {
	final BankServiceAsync bankService = GWT.create(BankService.class);
	private final RootPanel rootPanel = RootPanel.get("main");

	@Override
	public void onModuleLoad() {
		bankService.getDetails(new DefaultCallback<User>() {

			@Override
			public void onFailure(Throwable caught) {
				showLoginPage();
			}

			@Override
			public void onSuccess(User result) {
				showAccountDetailsPage(result);
			}
		});
	}

	void showLoginPage() {
		rootPanel.clear();
		rootPanel.add(new LoginPanel(this));
	}

	void showRegistrationPage() {
		rootPanel.clear();
		rootPanel.add(new RegistrationPanel(this));
	}

	void showAccountDetailsPage(User user) {
		rootPanel.clear();
		rootPanel.add(new AccountDetailsPanel(this, user));
	}

	void showTransferPage() {
		rootPanel.clear();
		rootPanel.add(new TransferPanel(this));
	}
}
